#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n, x, y;
		cin>>n;
		int ans = 0;
		for(int i = 1;i <= n;i++)
		{
			cin>>x>>y;
			ans += x == 0 ? 0 : x+(y-1)*20;
		}
		cout<<ans<<endl;
	}
	return 0;
}

